﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;

/// <summary>
///SmithHandle 的摘要说明
/// </summary>
public class SmithHandle
{
    public const int Img_W = 560;
    public const int Img_H = 560;
    public Color BackColor = Color.White;
    public Font textFont = new Font("Vernada", 12, FontStyle.Regular);
    public SmithHandle()
    { }
    
	public void SmithDraw(HttpContext context)
	{
        string type = context.Request.QueryString["type"];
        using (Image Graph_Smith = new Bitmap(560, 560))
        {

            using (Graphics G = Graphics.FromImage(Graph_Smith))
            {
                G.Clear(BackColor);

                switch (type)
                {
                    case "1":
                        SmithType1(context, G);
                        break;
                    case "2":
                        SmithType2(context, G);
                        break;
                    case "3":
                        SmithType3(context, G);
                        break;
                    case "4":
                        SmithType4(context, G);
                        break;
                    case "5":
                        SmithType5(context, G);
                        break;
                    case "6":
                        SmithType6(context, G);
                        break;
                    case "7":
                        SmithType7(context, G);
                        break;
                    case "8":
                        SmithType8(context, G);
                        break;
                    case "9":
                        SmithType9(context, G);
                        break;
                    case "10":
                        SmithType10(context, G);
                        break;
                    case "11":
                        SmithType11(context, G);
                        break;
                    case "12":
                        SmithType12(context, G);
                        break;
                    case "13":
                        SmithType13(context, G);
                        break;
                    case "14":
                        SmithType14(context, G);
                        break;
                    case "15":
                        SmithType15(context, G);
                        break;
                    case "16":
                        SmithType16(context, G);
                        break;
                }
            }

            using (MemoryStream stream = new MemoryStream())
            {
                Graph_Smith.Save(stream, ImageFormat.Png);
                //清除该页输出缓存，设置该页无缓存 
                context.Response.Buffer = false;
                context.Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0);
                context.Response.Expires = 0;
                context.Response.CacheControl = "no-cache";
                context.Response.AppendHeader("Pragma", "No-Cache");
                context.Response.ClearContent();
                context.Response.ContentType = "image/Png";
                context.Response.BinaryWrite(stream.ToArray());
            }
        }
	}

    void SmithType1(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var rcoef = context.Request.QueryString["Rcoef"];


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        if (string.IsNullOrEmpty(rcoef))
        {
            using (Pen mypen = new Pen(Color.SkyBlue, 2))
            {
                mypen.DashStyle = DashStyle.Solid;
                mypen.Color = Color.Black;
                mypen.Width = 3;
                float R_amp = 0.125f;
                int i;

                SmithChart1.SmithChar_BackGround(G);
                for (i = 0; i < 9; i++)
                {
                    SmithChart1.SmithChart_Rcoefficient(G, R_amp, mypen, true);

                    R_amp = (i + 1) * 0.125f;
                }
            }
        }
        else
        {
            using (Pen mypen = new Pen(Color.Black, 3))
            {
                mypen.DashStyle = DashStyle.Solid;
                SmithChart1.SmithChar_BackGround(G);
                SmithChart1.Draw_CoeffCircle(G, float.Parse(rcoef), mypen);
            }
        }

    }

    void SmithType2(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var flag = context.Request.QueryString["Z0"];
        var zlr = context.Request.QueryString["ZLR"];

        double temp = Convert.ToDouble(context.Request.QueryString["Z0"]);
        float Ramp = (float)temp;
        temp = Convert.ToDouble(zlr);
        float Z0 = (float)temp;
        Ramp = Ramp / Z0;

        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (string.IsNullOrEmpty(flag))
        {
            using (Pen mypen = new Pen(Color.SkyBlue, 2))
            {
                mypen.Color = Color.Blue;
                mypen.DashStyle = DashStyle.Solid;

                mypen.Width = 3;
                int i = 0;
                bool testDis;
                float Resistor = 0.0f;
                for (i = 0; i < 9; i++)
                {
                    if (i % 2 == 0)
                        testDis = true;
                    else
                        testDis = false;
                    SmithChart1.SmithChart_Resistor(G, Resistor, testDis, mypen);
                    Resistor = (i + 1) * 0.25f;
                }
            }
        }
        else
        {
            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                mypen.DashStyle = DashStyle.Solid;
                SmithChart1.Draw_RCircle(G, Ramp, mypen);  
            }
        }
    }
    
    void SmithType3(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var flag = context.Request.QueryString["Z0"];
        var zlr = context.Request.QueryString["ZLR"];

        double temp = Convert.ToDouble(context.Request.QueryString["Z0"]);
        float Xamp = (float)temp;
        temp = Convert.ToDouble(zlr);
        float Z0 = (float)temp;
        Xamp = Xamp / Z0;

        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (string.IsNullOrEmpty(flag))
        {
            using (Pen mypen = new Pen(Color.SkyBlue, 2))
            {
                mypen.DashStyle = DashStyle.Solid;
                mypen.Color = Color.DodgerBlue;
                mypen.Width = 3;

                int i = 0;
                float x = 0.25f;
                bool TextDis = true;
                for (i = 1; i < 9; i++)
                {
                    SmithChart1.SmithChart_X(G, x, TextDis, mypen);
                    SmithChart1.SmithChart_X(G, -x, TextDis, mypen);
                    x = (i + 1) * 0.25f;
                }
            }
        }
        else
        {
            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                mypen.DashStyle = DashStyle.Solid;
                SmithChart1.Draw_Xcircle(G, Xamp, mypen);  
            }
        }
    }

    void SmithType4(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        string subType = context.Request.QueryString["subType"];

        if (string.IsNullOrEmpty(subType))
        {
            subType = "1";
        }

        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);


        if (subType.Equals("1"))
        {
            SmithChart1.SmithChar_Orign(G);
            SmithChart1.Draw_OpenPoint(G);
        }
        else if (subType.Equals("2"))
        {
            SmithChart1.SmithChar_Orign(G);
            SmithChart1.Draw_ShortPoint(G);
        }
        else if (subType.Equals("3"))
        {
            SmithChart1.SmithChar_Orign(G);
            SmithChart1.Draw_MatchPoint(G);
        }
        else if (subType.Equals("4"))
        {
            SmithChart1.SmithChar_Orign(G);
            SmithChart1.Draw_MatchCircle(G);
        }
        else if (subType.Equals("5"))
        {
            SmithChart1.SmithChar_Orign(G);
            SmithChart1.Draw_ResistorLine(G);
        }
    }

    void SmithType5(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        SmithChart1.SmithChar_Orign(G);
    }

    void SmithType6(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"])?-1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step >-1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);

                }
                if (step> 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);

                }
                if (step >2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);

                }
                if (step >3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);

                }
                if (step >4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);

                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1); //和外边圆相交点
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, true);

                }
                if (step >5)
                {
                    if (cB_L_Unit == 0)
                    {
                        while (LtoZL > 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    else
                    {
                        lamda = 300000000 / freq;
                        temp1 = LtoZL / lamda;
                        while (LtoZL > 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1); //和外边圆相交点
                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, false);

                }
                if (step >6)
                {
                    if (cB_L_Unit == 0)
                    {
                        while (LtoZL >= 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    else
                    {
                        lamda = 300000000 / freq;
                        temp1 = LtoZL / lamda;
                        while (LtoZL > 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                    mypen.Color = Color.Red;
                    crossP = SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                    mypen.Color = Color.Brown;
                    mypen.EndCap = LineCap.NoAnchor;
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi - Phi_vari, false);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi - Phi_vari, Rcoef);
                    mypen.Color = Color.Red;
                    SmithChart1.DrawCrossP(G, crossP);
                    mypen.Color = Color.Brown;
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);

                }
               
            }

        }

    }

    void SmithType7(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;

                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);

                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1); //和外边圆相交点
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, true);
                }
                if (step > 5)
                {
                    if (cB_L_Unit == 0)
                    {
                        while (LtoZL >= 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    else
                    {
                        lamda = 300000000 / freq;
                        temp1 = LtoZL / lamda;
                        while (LtoZL > 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                    mypen.Color = Color.Red;
                    crossP = SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 6)
                {
                    if (cB_L_Unit == 0)
                    {
                        while (LtoZL >= 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    else
                    {
                        lamda = 300000000 / freq;
                        temp1 = LtoZL / lamda;
                        while (LtoZL > 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                    mypen.Color = Color.Red;
                    crossP = SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);
                    mypen.Color = Color.Brown;
                    mypen.EndCap = LineCap.NoAnchor;
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi - Phi_vari, false);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi - Phi_vari, Rcoef);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 7)
                {
                    if (cB_L_Unit == 0)
                    {
                        while (LtoZL >= 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    else
                    {
                        lamda = 300000000 / freq;
                        temp1 = LtoZL / lamda;
                        while (LtoZL > 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                    mypen.Color = Color.Red;
                    crossP = SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);
                    mypen.Color = Color.Brown;
                    mypen.EndCap = LineCap.NoAnchor;
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi - Phi_vari, false);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi - Phi_vari, Rcoef);
                    SmithChart1.DrawCrossP(G, crossP);
                    float rFrom = SmithChart1.Cal_RfromCrossP(crossP);
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, rFrom, true, mypen);
                }
                if (step > 8)
                {
                    if (cB_L_Unit == 0)
                    {
                        while (LtoZL >= 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    else
                    {
                        lamda = 300000000 / freq;
                        temp1 = LtoZL / lamda;
                        while (LtoZL > 0.5f)
                            LtoZL -= 0.5f;
                        Phi_vari = (float)(4 * Math.PI * LtoZL);
                    }
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                    mypen.Color = Color.Red;
                    crossP = SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);
                    mypen.Color = Color.Brown;
                    mypen.EndCap = LineCap.NoAnchor;
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi - Phi_vari, false);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi - Phi_vari, Rcoef);
                    SmithChart1.DrawCrossP(G, crossP);
                    Ramp = SmithChart1.Cal_RfromCrossP(crossP);
                    mypen.Color = Color.DodgerBlue;
                    Xamp = SmithChart1.Cal_XfromCrossP(crossP);
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }

            }
        }

    }

    void SmithType8(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);

                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);

                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);

                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);

                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);

                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1); //和外边圆相交点
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, true);

                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1); //和外边圆相交点
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    mypen.Color = Color.Red;

                    if (Xamp > 0)
                    {
                        LtoZL = 0.25f - Phi_lamda;
                        Phi_vari = Rcoef_phi;
                    }
                    else
                    {
                        LtoZL = (0.5f - Phi_lamda + 0.25f);
                        Phi_vari = Rcoef_phi;
                    }
                    crossP = SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);

                }


            }

        }
    }

    void SmithType9(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);

                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);

                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1); //和外边圆相交点
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, true);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1); //和外边圆相交点
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    mypen.Color = Color.Red;

                    if (Xamp > 0)
                    {
                        LtoZL = 0.5f - Phi_lamda;
                        Phi_vari = Rcoef_phi + (float)Math.PI;
                    }
                    else
                    {
                        LtoZL = 0.5f - Phi_lamda;
                        Phi_vari = Rcoef_phi - (float)(Math.PI);
                    }
                    crossP = SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);
                }

            }

        }
    }

    void SmithType10(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    crossP = SmithChart1.Cal_LineCrossPoint(0, Rcoef);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    crossP = SmithChart1.Cal_LineCrossPoint(0, Rcoef);
                    Ramp = SmithChart1.Cal_RfromCrossP(crossP);
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                }

            }

        }
    }

    void SmithType11(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)Math.PI;
                    crossP = SmithChart1.Cal_LineCrossPoint(temp1, Rcoef);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)Math.PI;
                    crossP = SmithChart1.Cal_LineCrossPoint(temp1, Rcoef);
                    Ramp = SmithChart1.Cal_RfromCrossP(crossP);
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                }

            }

        }
    }

    void SmithType12(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    crossP = SmithChart1.Cal_LineCrossPoint(Rcoef_phi, 1);
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, true);
                    if (Phi_lamda > 0.25)
                        LtoZL = 0.5f - Phi_lamda;
                    else
                        LtoZL = 0.25f - Phi_lamda;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    lamda = 300000000 / freq;
                    LtoZL = LtoZL * lamda;
                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, false);
                    SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, false);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Brown;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    if (Rcoef_phi > Math.PI)
                        temp1 = (float)Math.PI;
                    else
                        temp1 = 0;
                    crossP = SmithChart1.Cal_LineCrossPoint(temp1, Rcoef);
                    SmithChart1.DrawCrossP(G, crossP);
                    Ramp = SmithChart1.Cal_RfromCrossP(crossP);
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);

                }

            }

        }
    }

    void SmithType13(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 1)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 2)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    temp1 = (float)(Rcoef_phi / Math.PI * 180);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {

                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    mypen.Color = Color.Red;
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[0], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[0]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                }
                if (step > 6)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 7)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    lamda = 300000000 / freq;
                    //LtoZL = temp1 - 0.25f;
                    //if (LtoZL < 0)
                    //    LtoZL = 0.5f + LtoZL;
                    LtoZL = temp1;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    mypen.Color = Color.Red;
                    SmithChart1.Draw_ShortPoint(G);
                    SmithChart1.CalandDraw_ArrowArc(G, 1, (float)Math.PI, Phi_vari, mypen, true);
                }
                if (step > 8)
                {
                    G.Clear(BackColor);
                    SmithChart1.SmithChar_BackGround(G);
                    mypen.Width = 3;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    mypen.Color = Color.DodgerBlue;
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[1], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[1]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 9)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[1]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, false, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    SmithChart1.DrawCrossP(G, crossP);
                    lamda = 300000000 / freq;
                    //LtoZL = temp1 - 0.25f;
                    //if (LtoZL < 0)
                    //    LtoZL = 0.5f + LtoZL;
                    LtoZL = temp1 * lamda;
                    Phi_vari = (float)(4 * Math.PI * temp1);

                    mypen.Color = Color.Red;
                    SmithChart1.Draw_ShortPoint(G);
                    SmithChart1.CalandDraw_ArrowArc(G, 1, (float)Math.PI, Phi_vari, mypen, true);
                }

            }

        }
    }

    void SmithType14(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 1)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 2)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount != 1)
                    {
                        SmithChart1.DrawCrossP(G, PointArray[0]);
                        SmithChart1.DrawCrossP(G, PointArray[1]);
                    }
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    mypen.Color = Color.Red;
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[0], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[0]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                    //SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                }
                if (step > 6)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {

                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 7)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {

                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, false, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    lamda = 300000000 / freq;
                    LtoZL = temp1 - 0.25f;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    //LtoZL = temp1 - 0.5f;
                    //if (LtoZL < 0)
                    //    LtoZL = 0.5f + LtoZL;                                
                    LtoZL = LtoZL * lamda;
                    Phi_vari = (float)(4 * Math.PI * (temp1 - 0.25f));

                    mypen.Color = Color.Red;
                    SmithChart1.Draw_OpenPoint(G);
                    SmithChart1.CalandDraw_ArrowArc(G, 1, 0, Phi_vari, mypen, true);

                }
                if (step > 8)
                {
                    G.Clear(BackColor);
                    SmithChart1.SmithChar_BackGround(G);
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    mypen.Color = Color.Black;
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[1], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[1]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 9)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {

                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[1]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    SmithChart1.DrawCrossP(G, crossP);
                    lamda = 300000000 / freq;
                    LtoZL = temp1 - 0.25f;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    if (Phi_vari < 0)
                        Phi_vari = -Phi_vari;
                    LtoZL = LtoZL * lamda;

                    mypen.Color = Color.Red;
                    SmithChart1.Draw_OpenPoint(G);
                    SmithChart1.CalandDraw_ArrowArc(G, 1, 0, Phi_vari, mypen, true);


                }

            }
        }
    }

    void SmithType15(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;
            Ramp = Y.X;
            Xamp = Y.Y;
            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    G.Clear(BackColor);
                    SmithChart1.SmithChart_Y_BG(G);
                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                }
                if (step > 4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    mypen.Color = Color.Red;
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[0], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[0]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                    //SmithChart1.CalandDraw_ArrowArc(G, 1, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 6)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                }
                if (step > 7)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 8)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    lamda = 300000000 / freq;
                    LtoZL = temp1 - 0.25f;
                    if (LtoZL < 0)
                        LtoZL += 0.5f;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, 1, 0, Phi_vari, mypen, true);
                }
                if (step > 9)
                {
                    G.Clear(BackColor);
                    SmithChart1.SmithChart_Y_BG(G);
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    mypen.Color = Color.DodgerBlue;
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[1], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[1]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 10)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[1]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    SmithChart1.DrawCrossP(G, crossP);
                    lamda = 300000000 / freq;
                    LtoZL = temp1 - 0.25f;
                    if (LtoZL < 0)
                        LtoZL += 0.5f;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    mypen.Color = Color.Red;
                    SmithChart1.Draw_ShortPoint(G);
                    SmithChart1.CalandDraw_ArrowArc(G, 1, 0, Phi_vari, mypen, true);

                }

            }

        }
    }

    void SmithType16(HttpContext context, Graphics G)
    {
        G.Clear(BackColor);
        var step = string.IsNullOrEmpty(context.Request.QueryString["step"]) ? -1 : int.Parse(context.Request.QueryString["step"]);


        Point Center = new Point();
        Center.X = Img_W / 2;
        Center.Y = Img_H / 2;
        G.TranslateTransform(Center.X, Center.Y);
        SmithChart SmithChart1 = new SmithChart(Img_W, Img_H);
        SmithChart1.SmithChar_BackGround(G);
        if (step > -1)
        {


            float Ramp;
            float Xamp;
            float Z0;
            float Rcoef;
            float Rcoef_phi;
            float LtoZL;
            float temp1, temp2;
            float freq;
            float lamda;
            float Phi_lamda;
            string str;
            float Phi_vari;
            int cB_L_Unit = int.Parse(context.Request.QueryString["cB_L_Unit"]);

            PointF Z = new PointF();
            PointF Y = new PointF();

            Z0 = (float)(Convert.ToDouble(context.Request.QueryString["tB_Z0"]));
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_R"]));
            Ramp = temp1 / Z0;
            temp1 = (float)(Convert.ToDouble(context.Request.QueryString["tB_ZL_X"]));
            Xamp = temp1 / Z0;
            freq = (float)(Convert.ToDouble(context.Request.QueryString["tb_Freq"])) * 1000000;
            LtoZL = (float)(Convert.ToDouble(context.Request.QueryString["tb_L"]));
            Z.X = Ramp;
            Z.Y = Xamp;
            Y = SmithChart1.Cal_Z2Y(Z);
            PointF crossP = new PointF();
            PointF[] PointArray = new PointF[2];
            int iCount;
            Ramp = Y.X;
            Xamp = Y.Y;

            using (Pen mypen = new Pen(Color.Blue, 3))
            {
                step++;
                mypen.DashStyle = DashStyle.Solid;
                if (step > 0)
                {
                    G.Clear(BackColor);
                    SmithChart1.SmithChart_Y_BG(G);
                }
                if (step > 1)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    SmithChart1.SmithChart_Resistor(G, Ramp, true, mypen);
                    mypen.Color = Color.DodgerBlue;
                    SmithChart1.SmithChart_X(G, Xamp, true, mypen);
                }
                if (step > 2)
                {
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 3)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Black;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, true);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                }
                if (step >4)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);
                }
                if (step > 5)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    mypen.Color = Color.Red;
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[0], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[0]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 6)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                }
                if (step > 7)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    SmithChart1.DrawCrossP(G, crossP);
                }
                if (step > 8)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[0]);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    lamda = 300000000 / freq;
                    LtoZL = temp1;
                    //if (LtoZL < 0)
                    //    LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, 1, (float)Math.PI, Phi_vari, mypen, true);
                }
                if (step > 9)
                {
                    G.Clear(BackColor);
                    SmithChart1.SmithChart_Y_BG(G);
                    mypen.Width = 3;
                    mypen.Color = Color.Blue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    SmithChart1.SmithChart_Resistor(G, 1, true, mypen);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    SmithChart1.DrawCrossP(G, PointArray[0]);
                    SmithChart1.DrawCrossP(G, PointArray[1]);

                    Phi_lamda = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, PointArray[1], false);

                    lamda = 300000000 / freq;
                    LtoZL = temp1 - Phi_lamda;
                    if (LtoZL < 0)
                        LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    temp1 = SmithChart1.Cal_PhaseFromCrossP(PointArray[1]);
                    ///////////////////////////////////////////////////////////////////////////////
                    SmithChart1.Draw_lineFromOrign(G, mypen, Rcoef_phi, true);
                    SmithChart1.Draw_lineFromOrign(G, mypen, temp1, true);
                    ///////////////////////////////////////////////////////////////////////////
                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, Rcoef, Rcoef_phi, Phi_vari, mypen, true);
                }
                if (step > 10)
                {
                    mypen.Width = 3;
                    mypen.Color = Color.DodgerBlue;
                    crossP = SmithChart1.SmithChart_R_and_X(Ramp, Xamp);
                    Rcoef = SmithChart1.CalandDrawRcoef(G, mypen, crossP, false);
                    Rcoef_phi = SmithChart1.Cal_PhaseFromCrossP(crossP);
                    PointArray = SmithChart1.Cal_CrossPointFromRcoefandR(1, Rcoef, out iCount);
                    if (iCount == 1)
                    {
                        return;
                    }
                    temp1 = SmithChart1.Cal_XfromCrossP(PointArray[1]);
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    temp1 = -temp1;
                    SmithChart1.SmithChart_X(G, temp1, true, mypen);
                    crossP = SmithChart1.SmithChart_R_and_X(0, temp1);
                    temp1 = SmithChart1.CalandDraw_LineFromOrign(G, mypen, crossP, false);
                    SmithChart1.DrawCrossP(G, crossP);
                    lamda = 300000000 / freq;
                    LtoZL = temp1;
                    //if (LtoZL < 0)
                    //    LtoZL = 0.5f + LtoZL;
                    Phi_vari = (float)(4 * Math.PI * LtoZL);
                    LtoZL = LtoZL * lamda;

                    mypen.Color = Color.Red;
                    SmithChart1.CalandDraw_ArrowArc(G, 1, (float)Math.PI, Phi_vari, mypen, true);
                }
            }

        }
    }



   public  class SmithChart
    {
        private int mywidth;
        private int myheight;

        public SmithChart(int height, int width)
        {
            mywidth = width - 100;
            myheight = height - 100;
        }

        /// <summary>
        /// Smithchart's width
        /// </summary>
        public int ChartWidth
        {
            get
            {
                return mywidth;
            }
            set
            {
                mywidth = ChartWidth;
            }
        }

        /// <summary>
        /// SmithChart's height
        /// </summary>
        public int ChartHeight
        {
            get
            {
                return myheight;
            }
            set
            {
                myheight = ChartHeight;
            }
        }

        /// <summary>
        /// Rcoefficient is drawed by Fu*Fu+Fv*Fv=R*R (Rcoefficient=Fu+jFv=|F|exp(jphi)); Rcoefficient=(Zin-Z0)/(Zin+Z0); R(z)=|FL|exp(phiL-2*Beta*z);
        /// </summary>
        /// <remarks>phi and phiL is angle in radian</remarks>
        public int SmithChart_Rcoefficient(Graphics g, float R_amp, Pen linepen, bool TextDisplay)
        {
            if (R_amp > 1.0000)
                return -1;
            if (R_amp < 0)
                return -1;
            float R = (R_amp * mywidth / 2);
            float D = 2 * R;
            RectangleF Rect = new RectangleF(-R, -R, D, D);
            g.DrawEllipse(linepen, Rect);

            if (TextDisplay)
            {
                PointF point1 = new PointF();
                string str;
                point1.X = -10;
                point1.Y = R - 13;
                str = R_amp.ToString();
                g.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Purple), point1);
                point1.Y = -R + 3;
                g.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Purple), point1);
            }

            return 0;

        }

        /// <summary>
        /// the function draw the chart for resistor which equation is (Fu-Rcoef/(1+Rcoef))2+Fv2=(1/(1+Rcoef))2
        /// </summary>
        /// <remarks>Input Parameter: G, the canvas; R, the resitor; Linepen, pen used  when draw the chart</remarks>
        public void SmithChart_Resistor(Graphics G, float Resistor, bool TextDisplay, Pen LinePen)
        {
            float r1, r2;
            string str;
            r1 = 1 / (1 + Resistor);
            r2 = Resistor * r1;
            RectangleF Rect;
            float left = (r2 - r1) * mywidth / 2;
            float Top = -r1 * mywidth / 2;
            float width = r1 * 2 * mywidth / 2;
            float height = width;
            Rect = new RectangleF(left, Top, width, height);

            G.DrawEllipse(LinePen, Rect);
            // G.DrawLine(LinePen, new P(-mywidth / 2, 0), new P(mywidth / 2, 0));
            if (TextDisplay)
            {
                //str = "R=" + Resistor.ToString();
                str = Resistor.ToString();
                G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(left - 10, -15));
            }
        }

        /// <summary>
        /// the function to draw X chart, point of circle is (0,1/x), R is 1/x, from (1,0) to (1-2/(x(x+2)),2/(x+2)) using drawarc.
        /// </summary>
        public void SmithChart_X(Graphics G, float X, bool TextDisplay, Pen LinePen)
        {
            if (X == 0)
                return;
            float R, Center_Y;
            float temp;
            float angle1, angle2;
            float sweepAngle;
            R = 1 / X;
            Center_Y = R;
            RectangleF rect1 = new RectangleF();
            if (X > 0)
            {
                rect1.X = (1 - R) * mywidth / 2;
                rect1.Y = -2 / X * mywidth / 2;
                rect1.Width = 2 / X * mywidth / 2;
                rect1.Height = 2 / X * mywidth / 2;
                angle1 = 90;
                temp = 1 - 2 / (X * X + 1); // connective point 's X
                temp = 1 - temp; // angle's edge 's width
                angle2 = (float)Math.Acos(temp / R);
                if (X > 1)
                    angle2 = (float)(180 + angle2 / 2 / Math.PI * 360);
                else
                    angle2 = (float)(180 - angle2 / 2 / Math.PI * 360);
                sweepAngle = angle2 - angle1;
                G.DrawArc(LinePen, rect1, angle1, sweepAngle);

            }
            else
            {
                rect1.X = (1 + R) * mywidth / 2;
                rect1.Y = 0;
                rect1.Width = -2 / X * mywidth / 2;
                rect1.Height = -2 / X * mywidth / 2;
                angle1 = 270;
                temp = 1 - 2 / (X * X + 1); // connective point 's X
                temp = 1 - temp; // angle's edge 's width
                angle2 = (float)Math.Acos(-temp / R);
                if (X > -1)
                    angle2 = (float)(180 + angle2 / 2 / Math.PI * 360);
                else
                    angle2 = (float)(180 - angle2 / 2 / Math.PI * 360);
                sweepAngle = angle2 - angle1;
                G.DrawArc(LinePen, rect1, angle1, sweepAngle);

            }

            if (TextDisplay)
            {
                PointF point1 = new PointF();
                string str;
                point1.X = (1 - 2 / (X * X + 1)) * mywidth / 2;
                point1.Y = -2 * X / (X * X + 1) * myheight / 2;
                //point1.X = point1.X * (1 - 0.01f * point1.X);
                //point1.Y = point1.Y * (1 - 0.01f);
                //str = "X=" + X.ToString();
                str = X.ToString();
                G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Black), point1);
            }

        }

        /// <summary>
        /// SmithChart basic type;
        /// </summary>
        public int SmithChar_Orign(Graphics G)
        {
            AdjustableArrowCap lineArrow = new AdjustableArrowCap(4, 4, true);

            Pen mypen = new Pen(Color.Purple, 2);
            mypen.DashStyle = DashStyle.Solid;
            mypen.Color = Color.Sienna;
            mypen.Width = 3;
            mypen.EndCap = LineCap.Custom;
            mypen.CustomEndCap = lineArrow;

            G.DrawLine(mypen, new PointF(-mywidth / 2 - 25, 0), new PointF(mywidth / 2 + 25, 0));
            G.DrawLine(mypen, new PointF(0, myheight / 2 + 25), new PointF(0, -myheight / 2 - 25));
            Rectangle Rect = new Rectangle(-mywidth / 2 - 25, -myheight / 2 - 25, mywidth + 50, myheight + 50);
            G.DrawArc(mypen, Rect, 185, 30);
            G.DrawArc(mypen, Rect, 175, -30);

            mypen.Width = 2;
            mypen.EndCap = LineCap.NoAnchor;
            mypen.Color = Color.Black;

            float R_amp = 0.25f;
            int i;
            int RetValue;
            for (i = 0; i < 5; i++)
            {
                RetValue = SmithChart_Rcoefficient(G, R_amp, mypen, true);
                if (RetValue != 0)
                {
                    return RetValue;
                }
                R_amp = (i + 1) * 0.25f;
            }

            R_amp = 0.25f;
            mypen.Color = Color.Blue;
            for (i = 0; i < 5; i++)
            {

                SmithChart_Resistor(G, R_amp, true, mypen);
                R_amp = 2 * R_amp;
            }
            // SmithChart_Resistor(G, 0.25f, true, mypen);
            SmithChart_Resistor(G, 0f, true, mypen);

            //mypen.Color = Color.Tomato;
            mypen.Color = Color.DodgerBlue;
            R_amp = 0.5f;
            bool TextDis = true;
            for (i = 1; i < 5; i++)
            {
                SmithChart_X(G, R_amp, TextDis, mypen);
                SmithChart_X(G, -R_amp, TextDis, mypen);
                R_amp = 2 * R_amp;
            }
            mypen.Color = Color.Black;
            RetValue = SmithChart_Rcoefficient(G, 1, mypen, true);

            mypen.Color = Color.Purple;
            float ArcAngle;
            ArcAngle = (float)(45 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);
            ArcAngle = (float)(135 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);
            ArcAngle = (float)(225 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);
            ArcAngle = (float)(315 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);

            G.DrawString("向电源", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-mywidth / 2, -myheight / 4 - 50));
            G.DrawString("向负载", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-mywidth / 2, myheight / 4 + 40));

            G.DrawString("0λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-mywidth / 2 - 50, -10));
            G.DrawString("0.25λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(mywidth / 2 + 10, -10));
            G.DrawString("0.125λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-20, -myheight / 2 - 40));
            G.DrawString("0.375λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-20, myheight / 2 + 25));


            return RetValue;
        }

        /// <summary>
        /// the backgorund of SmithChart when question is solved by smithchart
        /// </summary>
        public int SmithChar_BackGround(Graphics G)
        {
            AdjustableArrowCap lineArrow = new AdjustableArrowCap(4, 4, true);

            Pen mypen = new Pen(Color.Purple, 2);
            mypen.DashStyle = DashStyle.Solid;
            mypen.Color = Color.Sienna;
            mypen.Width = 3;
            mypen.EndCap = LineCap.Custom;
            mypen.CustomEndCap = lineArrow;

            G.DrawLine(mypen, new PointF(-mywidth / 2 - 25, 0), new PointF(mywidth / 2 + 25, 0));
            G.DrawLine(mypen, new PointF(0, myheight / 2 + 25), new PointF(0, -myheight / 2 - 25));
            Rectangle Rect = new Rectangle(-mywidth / 2 - 25, -myheight / 2 - 25, mywidth + 50, myheight + 50);
            G.DrawArc(mypen, Rect, 185, 30);
            G.DrawArc(mypen, Rect, 175, -30);

            mypen.Width = 2;
            mypen.EndCap = LineCap.NoAnchor;

            int RetValue;

            float R_amp = 1f;

            mypen.Color = Color.Purple;

            RetValue = SmithChart_Rcoefficient(G, 1, mypen, true);

            float ArcAngle;
            ArcAngle = (float)(45 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);
            ArcAngle = (float)(135 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);
            ArcAngle = (float)(225 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);
            ArcAngle = (float)(315 * Math.PI / 180);
            Draw_lineFromOrign(G, mypen, ArcAngle, true);

            G.DrawString("向电源", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-mywidth / 2, -myheight / 4 - 50));
            G.DrawString("向负载", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-mywidth / 2, myheight / 4 + 40));

            G.DrawString("0λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-mywidth / 2 - 50, -10));
            G.DrawString("0.25λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(mywidth / 2 + 10, -10));
            G.DrawString("0.125λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-20, -myheight / 2 - 40));
            G.DrawString("0.375λ", new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), new PointF(-20, myheight / 2 + 25));

            return RetValue;
        }

        public System.Drawing.PointF SmithChart_R_and_X(float R, float X)
        {
            float temp;
            temp = (1 + R) * (1 + R) + X * X;
            PointF Res = new PointF();
            Res.X = 2 * (1 + R) / temp;
            Res.X = 1 - Res.X;
            Res.Y = 2 * X / temp;

            return Res;
        }

        /// <summary>
        /// draw a small red circle in smithchart by Cross point (x,y); 
        /// </summary>
        public void DrawCrossP(Graphics G, PointF P)
        {
            SolidBrush myBrush = new SolidBrush(Color.Red);
            RectangleF Rect = new RectangleF(P.X * mywidth / 2 - 3.5f, -P.Y * myheight / 2 - 3.5f, 7, 7);
            G.FillEllipse(myBrush, Rect);
        }
        /// <summary>
        /// Calacute the reflect coeffience by cross point (x,y). when isDraw, draw the reflect circle with Rcoef = sqrt(x*x+y*y)
        /// </summary>
        public float CalandDrawRcoef(Graphics G, Pen pen1, PointF P, bool isDraw)
        {
            float Ramp;
            Ramp = P.X * P.X + P.Y * P.Y;
            Ramp = (float)Math.Sqrt(Ramp);
            if (isDraw)
                SmithChart_Rcoefficient(G, Ramp, pen1, true);
            return Ramp;
        }

        /// <summary>
        /// calacute the SWR with Reflect coeffience
        /// </summary>
        public float SmithChart_SWR(Graphics G, Pen pen1, float Rcoef)
        {
            float R;
            R = (1 - Rcoef) / 2;
            R = (float)(1 / R);
            R = R - 1;
            SmithChart_Resistor(G, R, true, pen1);
            return R;
        }
        /// <summary>
        /// calacute travel wave ratio with refelct coeffience 
        /// </summary>
        public float SmithChart_TRC(Graphics G, Pen pen1, float Rcoef)
        {
            float R;
            R = (1 + Rcoef) / 2;
            R = (float)(1 / R);
            R = R - 1;
            SmithChart_Resistor(G, R, true, pen1);
            return R;
        }
        /// <summary>
        /// calacute the phase of reflect coeffience with Cross point
        /// </summary>
        public float Cal_PhaseFromCrossP(PointF p)
        {
            float phase;
            double angle;
            angle = p.Y / p.X;
            if (angle == 0)
            {
                if (p.X > 0)
                    angle = 0;
                else
                    angle = Math.PI;

            }
            else if (angle > 0)
            {
                if (p.X > 0)
                    angle = Math.Atan(angle);
                else
                    angle = Math.Atan(angle) + Math.PI;
            }
            else
            {
                if (p.X < 0)
                    angle = Math.PI + Math.Atan(angle);
                else
                    angle = 2 * Math.PI + Math.Atan(angle);
            }
            phase = (float)angle;
            return phase;
        }
        /// <summary>
        /// calacute the cross point (x,y) of Rcoef circle and line with pase from origin, then return (x,y)
        /// </summary>
        public PointF Cal_LineCrossPoint(float phase, float Rcoef)
        {
            PointF CrossPoint = new PointF();
            CrossPoint.X = Rcoef * ((float)Math.Cos(phase));
            CrossPoint.Y = Rcoef * ((float)Math.Sin(phase));
            return CrossPoint;
        }
        /// <summary>
        /// draw the line form orign to the circle with Rcoef = 1,and calacute the length from power source with lamda unit. if isTextDisp, Disp the length from power source
        /// </summary>
        public float CalandDraw_LineFromOrign(Graphics G, Pen linePen, PointF CrossPoint, bool isTextDisp)
        {
            PointF Orign = new PointF();
            Orign.X = 0;
            Orign.Y = 0f;
            PointF CrossP = new PointF();
            CrossP.X = CrossPoint.X * mywidth / 2;
            CrossP.Y = CrossPoint.Y * (-myheight / 2);
            G.DrawLine(linePen, Orign, CrossP);

            float phi;
            float phi_lamda;
            phi = Cal_PhaseFromCrossP(CrossPoint);
            if (phi < Math.PI)
                phi_lamda = (float)(1.0f / 4 - phi / 2 / Math.PI / 2);
            else
                phi_lamda = (float)(1.0f / 2 - phi / 2 / Math.PI / 2 + 0.25);
            if (isTextDisp)
            {
                PointF p = new PointF();
                p.X = CrossPoint.X * mywidth / 2 - 50;
                p.Y = -CrossPoint.Y * mywidth / 2;
                string str = phi_lamda.ToString() + "λ";
                G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);
            }
            return phi_lamda;

        }
        /// <summary>
        /// draw the line from orign  to circle of Rcoef=1 with phase. if isTextDisplay, Display the length from power source
        /// </summary>
        public void Draw_lineFromOrign(Graphics G, Pen linePen, float phase, bool isTextDisplay)
        {
            PointF CrossPoint = new PointF();

            //限制角度在 -PI < phase < pi 
            while (phase > Math.PI)
                phase = phase - (float)(2 * Math.PI);
            while (phase < -Math.PI)
                phase = phase = (float)(2 * Math.PI);

            CrossPoint = Cal_LineCrossPoint(phase, 1f);
            CrossPoint.X *= mywidth / 2;
            CrossPoint.Y *= -myheight / 2;
            PointF Orign = new PointF();
            Orign.X = 0;
            Orign.Y = 0f;
            G.DrawLine(linePen, Orign, CrossPoint);
            if (isTextDisplay)
            {
                float L;
                L = (float)(phase / 4 / Math.PI);
                L = 0.25f - L;
                string str;
                str = L.ToString() + "λ";
                PointF p = new PointF();
                if (CrossPoint.X > 0)
                {
                    p.X = CrossPoint.X * mywidth / 2 - 50;
                    if (CrossPoint.Y > 0)
                    {
                        p.Y = -CrossPoint.Y * mywidth / 2 + 10;
                        G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);
                    }
                    else
                    {
                        p.Y = -CrossPoint.Y * mywidth / 2 - 20;
                        G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);
                    }
                }
                else
                {
                    p.X = CrossPoint.X * mywidth / 2 + 55;
                    if (CrossPoint.Y > 0)
                    {
                        p.Y = -CrossPoint.Y * mywidth / 2;
                        G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);
                    }
                    else
                    {
                        p.Y = -CrossPoint.Y * mywidth / 2 - 20;
                        G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);
                    }
                }
            }
        }
        /// <summary>
        /// calacute the cross point (x,y) with the circle of Rcoef and line of phase from orign
        /// </summary>
        public PointF Cal_CrossPointFromRcoefandP(float Rcoef, PointF p)
        {
            PointF CrossPoint = new PointF();
            float ArcAngle;
            ArcAngle = Cal_PhaseFromCrossP(p);
            CrossPoint = Cal_LineCrossPoint(ArcAngle, Rcoef);
            return CrossPoint;
        }
        /// <summary>
        /// calacute the cross point (x1,y1),(x2,y2) with the circle of Rceof intersecting the circle of Resistor, and Count is the number of cross point, and return coordidate of cross point
        /// </summary>
        public PointF[] Cal_CrossPointFromRcoefandR(float R, float Rcoef, out int Count)
        {
            Count = 0;
            PointF[] CrossP = new PointF[2];

            //judge count=?
            float RR;
            float U;
            RR = R * R;
            float temp1, temp2;
            temp1 = (1 + R) / 2 / R;
            U = temp1;
            temp1 = temp1 * temp1;
            temp2 = (RR - 1) / (1 + R) / (1 + R);
            temp2 = Rcoef * Rcoef + temp2;
            U = temp2 * U;
            temp2 = temp2 * temp2;
            float condition;
            //condition = Rcoef * Rcoef - temp1 * temp2;
            condition = Rcoef * Rcoef - U * U;
            if (condition > 0)
            {
                Count = 2;
                CrossP[0].X = U;
                CrossP[0].Y = (float)(Math.Sqrt(condition));
                CrossP[1].X = U;
                CrossP[1].Y = -(float)(Math.Sqrt(condition));
            }
            if (condition == 0)
            {
                Count = 1;
                CrossP[1].X = U;
                CrossP[1].Y = 0;
            }
            if (condition < 0)
            {
                Count = 0;
            }

            return CrossP;
        }
        /// <summary>
        /// Calacute the Resitor through the corss point
        /// </summary>
        public float Cal_RfromCrossP(PointF CrossP)
        {
            float retR;
            float temp1, temp2;
            float temp3;
            temp1 = CrossP.X * CrossP.X + CrossP.Y * CrossP.Y;
            temp2 = temp1 - CrossP.X;
            temp2 = temp2 * temp2;
            temp3 = temp1 - 2 * CrossP.X + 1;
            temp2 = temp2 - temp3 * (temp1 - 1);
            temp2 = (float)(Math.Sqrt(temp2));
            temp2 = temp2 - temp1 + CrossP.X;
            retR = temp2 / temp3;
            return retR;
        }
        /// <summary>
        /// calacute the X through the crosspoint
        /// </summary>
        public float Cal_XfromCrossP(PointF CrossP)
        {
            float retX;
            float temp1, temp2;
            temp1 = (CrossP.X - 1);
            temp1 *= temp1;
            temp2 = CrossP.Y * CrossP.Y;
            temp1 = temp1 + temp2;
            temp2 = 2 * CrossP.Y;
            retX = temp2 / temp1;
            return retX;
        }
        /// <summary>
        /// Draw a small red circle on the open point 
        /// </summary>
        public void Draw_OpenPoint(Graphics G)
        {
            PointF p = new PointF();
            p.X = -1;
            p.Y = 0;
            SolidBrush myBrush = new SolidBrush(Color.Red);
            RectangleF Rect = new RectangleF(-p.X * mywidth / 2 - 4f, -p.Y * myheight / 2 - 4f, 8, 8);
            G.FillEllipse(myBrush, Rect);
            p.X = mywidth / 2 - 20;
            p.Y = -40;
            G.DrawString("开路点", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Red), p);
        }

        /// <summary>
        /// draw a small red circle on short point 
        /// </summary>
        public void Draw_ShortPoint(Graphics G)
        {
            PointF p = new PointF();
            p.X = 1;
            p.Y = 0;
            SolidBrush myBrush = new SolidBrush(Color.Red);

            RectangleF Rect = new RectangleF(-p.X * mywidth / 2 - 4f, -p.Y * myheight / 2 - 4f, 8, 8);
            G.FillEllipse(myBrush, Rect);
            p.X = -mywidth / 2 - 30;
            p.Y = -40;
            G.DrawString("短路点", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Red), p);
        }
        /// <summary>
        /// Draw a small red filled circle on match point
        /// </summary>
        public void Draw_MatchPoint(Graphics G)
        {
            PointF p = new PointF();
            p.X = 0;
            p.Y = 0;
            SolidBrush myBrush = new SolidBrush(Color.Red);
            RectangleF Rect = new RectangleF(-4f, -4f, 8, 8);
            G.FillEllipse(myBrush, Rect);
            p.X = -20;
            p.Y = -40;
            G.DrawString("匹配点", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Red), p);
        }
        /// <summary>
        /// Draw the red Resistor Circle with R=1
        /// </summary>
        public void Draw_MatchCircle(Graphics G)
        {
            Pen mypen = new Pen(Color.Red);
            mypen.Color = Color.Red;
            mypen.Width = 3;
            SmithChart_Resistor(G, 1, false, mypen);
            PointF p = new PointF();
            p.X = 0.3f * mywidth / 2;
            p.Y = -myheight / 4;
            G.DrawString("匹配圆R=1", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);

        }
        /// <summary>
        /// draw the resistor line with x=0
        /// </summary>
        public void Draw_ResistorLine(Graphics G)
        {
            Pen mypen = new Pen(Color.Red);
            mypen.Color = Color.Red;
            mypen.Width = 3;
            PointF p1 = new PointF();
            p1.X = -mywidth / 2;
            p1.Y = 0;
            PointF p2 = new PointF();
            p2.X = mywidth / 2;
            p2.Y = 0;
            G.DrawLine(mypen, p1, p2);

            p1.X = -0.4f * mywidth / 2;
            p1.Y = -0.2f * myheight / 2;
            p2.X = -0.7f * mywidth / 2;
            p2.Y = 0;
            mypen.Width = 2;
            mypen.Color = Color.Blue;
            AdjustableArrowCap lineArrow = new AdjustableArrowCap(4, 4, true);
            mypen.EndCap = LineCap.Custom;
            mypen.CustomEndCap = lineArrow;
            G.DrawLine(mypen, p1, p2);
            p1.Y = p1.Y - 10;

            G.DrawString("纯电阻线", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Red), p1);
        }
        /// <summary>
        /// Draw the rcoef circle with rcoef value
        /// </summary>
        public void Draw_CoeffCircle(Graphics G, float Rcoef, Pen linePen)
        {
            SmithChart_Rcoefficient(G, Rcoef, linePen, true);
            PointF p1 = new PointF();
            PointF p2 = new PointF();
            p1.X = Rcoef * 0.707f * mywidth / 2;
            p1.Y = -Rcoef * 0.707f * mywidth / 2;
            p2.X = 0;
            p2.Y = 0;
            linePen.Color = Color.Red;
            G.DrawLine(linePen, p1, p2);
            SolidBrush myBrush = new SolidBrush(Color.Red);
            PointF p = new PointF();
            p.X = p1.X / 2 - 40;
            p.Y = p1.Y / 2;
            string str;
            str = "Rcoef=" + Rcoef.ToString();
            G.DrawString(str, new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), myBrush, p);
        }
        /// <summary>
        /// Draw resisotr circle with linePen
        /// </summary>
        public void Draw_RCircle(Graphics G, float Ramp, Pen linePen)
        {
            SmithChart_Resistor(G, Ramp, true, linePen);
            PointF p1 = new PointF();
            PointF p2 = new PointF();
            float R;
            p1.X = Ramp / (Ramp + 1);
            R = 1 / (1 + Ramp);
            p1.X = p1.X * mywidth / 2;
            p1.Y = 0.0f;
            p2.X = p1.X + R * 0.707f * mywidth / 2;
            p2.Y = -R * mywidth / 2 * 0.707f;
            G.DrawLine(linePen, p1, p2);
            SolidBrush myBrush = new SolidBrush(Color.Red);
            PointF p = new PointF();
            p.X = (p1.X + p2.X) / 2 - 40;
            p.Y = (p1.Y + p2.Y) / 2;
            G.DrawString("R=1/(1+r)", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), myBrush, p);

            RectangleF Rect = new RectangleF(p1.X - 4f, -4f, 8, 8);

            G.FillEllipse(myBrush, Rect);
            p1.X = p1.X - 40;
            p1.Y = 10;
            G.DrawString("(0,r/(1+r))", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), myBrush, p1);
        }
        /// <summary>
        /// draw the x circle with x and linePen
        /// </summary>
        public void Draw_Xcircle(Graphics G, float Xamp, Pen linePen)
        {
            SmithChart_X(G, Xamp, false, linePen);
            PointF p1 = new PointF();
            p1.X = mywidth / 2;
            p1.Y = -1 / Xamp * mywidth / 2;
            SolidBrush myBrush = new SolidBrush(Color.Red);
            RectangleF Rect = new RectangleF(p1.X - 4f, p1.Y - 4f, 8, 8);
            G.FillEllipse(myBrush, Rect);
            PointF p = new PointF();
            p.X = p1.X - 50;
            p.Y = p1.Y + 10;

            G.DrawString("(1,1/x)", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), myBrush, p);

            PointF p2 = new PointF();
            float X;
            X = 1 / Xamp * mywidth / 2;
            p2.X = p1.X - Math.Abs(X) * 0.707f;
            p2.Y = p1.Y + X * 0.707f;
            linePen.Color = Color.Red;
            G.DrawLine(linePen, p1, p2);

            p.X = (p1.X + p2.X) / 2;
            p.Y = (p1.Y + p2.Y) / 2;
            G.DrawString("(0,r/(1+r))", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), myBrush, p);

        }
        /// <summary>
        /// cal the varied length to RL with orgin angle sweeping the sweep angle, and if isdisplamda, the length is displayed 
        /// </summary>
        public PointF CalandDraw_ArrowArc(Graphics G, float Rcoef, float OrignAngle, float SweepAngle, Pen linePen, bool isDispLamda)
        {
            double Rx, Ry;
            Rx = Rcoef;
            Ry = Rcoef;
            RectangleF Rect = new RectangleF();
            Rect.X = -(float)Rx * mywidth / 2;
            Rect.Y = -(float)Ry * mywidth / 2;
            Rect.Width = 2 * Rcoef * mywidth / 2;
            Rect.Height = 2 * Rcoef * mywidth / 2;
            double Ang1;
            double Ang2;
            Ang1 = OrignAngle / Math.PI * 180;
            Ang2 = SweepAngle / Math.PI * 180;
            AdjustableArrowCap lineArrow = new AdjustableArrowCap(4, 4, true);
            linePen.EndCap = LineCap.Custom;
            linePen.CustomEndCap = lineArrow;
            G.DrawArc(linePen, Rect, -(float)Ang1, (float)Ang2);

            float EndPhi_lamda;
            float EndPhi_lamda1;
            EndPhi_lamda = OrignAngle - SweepAngle;
            if (EndPhi_lamda < Math.PI)
                EndPhi_lamda1 = (float)(1.0f / 4 - EndPhi_lamda / 2 / Math.PI / 2);
            else
                EndPhi_lamda1 = (float)(1.0f / 2 - EndPhi_lamda / 2 / Math.PI / 2 + 0.25);
            PointF resP = new PointF();
            resP.X = (float)(Math.Cos(EndPhi_lamda));
            resP.Y = -(float)(Math.Sin(EndPhi_lamda));
            if (isDispLamda)
            {
                PointF p = new PointF();

                p.X = (float)(Math.Cos(EndPhi_lamda)) * mywidth / 2;
                p.Y = -(float)(Math.Sin(EndPhi_lamda)) * mywidth / 2;
                string str = EndPhi_lamda1.ToString() + "λ";
                G.DrawString(str, new Font(FontFamily.GenericMonospace, 9, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);
            }
            return resP;
        }
        /// <summary>
        /// draw the background of Y_SmithChart
        /// </summary>
        public void SmithChart_Y_BG(Graphics G)
        {
            SmithChar_BackGround(G);
            Draw_Y_OpenPoint(G);
            Draw_Y_ShortPoint(G);
            Draw_Y_Line(G);
            Draw_MatchPoint(G);
            Draw_Y_MatchCircle(G);
        }
        /// <summary>
        /// draw a small red circle with open point on Y_smithchart
        /// </summary>
        public void Draw_Y_OpenPoint(Graphics G)
        {
            PointF p = new PointF();
            p.X = 1;
            p.Y = 0;
            SolidBrush myBrush = new SolidBrush(Color.Red);
            RectangleF Rect = new RectangleF(-p.X * mywidth / 2 - 4f, -p.Y * myheight / 2 - 4f, 8, 8);
            G.FillEllipse(myBrush, Rect);
            p.X = -mywidth / 2 - 30;
            p.Y = -40;
            G.DrawString("开路点", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Red), p);
        }
        /// <summary>
        /// draw a small red circle with short point on Y_smithchart
        /// </summary>
        public void Draw_Y_ShortPoint(Graphics G)
        {
            PointF p = new PointF();
            p.X = -1;
            p.Y = 0;
            SolidBrush myBrush = new SolidBrush(Color.Red);
            RectangleF Rect = new RectangleF(-p.X * mywidth / 2 - 4f, -p.Y * myheight / 2 - 4f, 8, 8);
            G.FillEllipse(myBrush, Rect);
            p.X = mywidth / 2 - 20;
            p.Y = -40;
            G.DrawString("短路点", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Red), p);
        }

        public void Draw_Y_MatchCircle(Graphics G)
        {
            Pen mypen = new Pen(Color.Red);
            mypen.Color = Color.Red;
            mypen.Width = 3;
            SmithChart_Resistor(G, 1, false, mypen);
            PointF p = new PointF();
            p.X = 0.3f * mywidth / 2;
            p.Y = -myheight / 4;
            G.DrawString("匹配圆G=1", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Blue), p);

        }

        /// <summary>
        /// draw Y line with B=0 on Y_smithchart
        /// </summary>
        public void Draw_Y_Line(Graphics G)
        {
            Pen mypen = new Pen(Color.Red);
            mypen.Color = Color.Red;
            mypen.Width = 3;
            PointF p1 = new PointF();
            p1.X = -mywidth / 2;
            p1.Y = 0;
            PointF p2 = new PointF();
            p2.X = mywidth / 2;
            p2.Y = 0;
            G.DrawLine(mypen, p1, p2);

            p1.X = -0.4f * mywidth / 2;
            p1.Y = -0.2f * myheight / 2;
            p2.X = -0.7f * mywidth / 2;
            p2.Y = 0;
            mypen.Width = 2;
            mypen.Color = Color.Blue;
            AdjustableArrowCap lineArrow = new AdjustableArrowCap(4, 4, true);
            mypen.EndCap = LineCap.Custom;
            mypen.CustomEndCap = lineArrow;
            G.DrawLine(mypen, p1, p2);
            p1.Y = p1.Y - 10;

            G.DrawString("纯电导线", new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Point), new SolidBrush(Color.Red), p1);
        }

        /// <summary>
        /// calacute the Y from Z
        /// </summary>
        public PointF Cal_Z2Y(PointF Z)
        {
            float temp1, temp2;
            temp1 = Z.X * Z.X + Z.Y * Z.Y;
            temp2 = Z.Y / temp1;
            temp1 = Z.X / temp1;
            PointF Y = new PointF();
            Y.X = temp1;
            Y.Y = -temp2;
            return Y;
        }
        /// <summary>
        /// calacute Z from Y
        /// </summary>
        public PointF Cal_Y2Z(PointF Y)
        {
            return Cal_Z2Y(Y);
        }
    }
}